//
//  UgcMain_VC_WX.m
//  ZITHER
//
//  Created by weixin on 2018/9/10.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "UgcMain_VC_WX.h"
#import "UgcMain_First_Tbv_WX.h"

#import "failToSendView.h"

#define backHeight (Is_Iphone_X_Series ? kStatusBarHeight+10+20 : kStatusBarHeight+10+20+3)

@interface UgcMain_VC_WX ()

@property (nonatomic,strong)failToSendView * filaSendView;

@property (nonatomic,assign)BOOL isSelecet;//社交第二下跳到发布页面

@property (nonatomic,assign)BOOL isUserIsLogin;//登陆状态是否发生变化

@property (nonatomic,strong)UgcMain_First_Tbv_WX * tbv;


@end

@implementation UgcMain_VC_WX

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.isSelecet = YES;

    [self setNav];
    
//    [self loaddata];
    
    [self setUI];
    if ([Main_Token_Model_MANAGER.isToken isEqualToString:@"1"]) {
        self.view.backgroundColor = Main_Token_Model_MANAGER.backgroundColor ;
    }

}

-(void)setNav{
    [self.baseNavigationView setHiddenNav:YES VC:self];

    
}

-(void)loaddata{
    
}

-(void)Masonry{
    
}

-(void)setUI{
    
    self.view.backgroundColor = HexColor(0xf5f5f5);
    
    BaseView *bgView = [[BaseView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    if ([Main_Token_Model_MANAGER.isToken isEqualToString:@"1"]){
        bgView.backgroundColor = Main_Token_Model_MANAGER.backgroundColor ;
    }else{
        bgView.backgroundColor = [UIColor whiteColor];
        
    }
    [self.view addSubview:bgView];
    [self.view addSubview:self.tbv];
    [self.view addSubview:self.TitleV];
    
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view).offset(0);
        make.bottom.equalTo(self.TitleV.mas_bottom).offset(0);
    }];
    


    [self.tbv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view).offset(0);
        make.bottom.equalTo(self.view).offset(-49-kBottomSafeHeight);
        make.top.equalTo(self.TitleV.mas_bottom).offset(0);
    }];

//    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, kScreenH-kStatusBarHeight-60)];
//    [view addSubview:self.scroView];
//    [view addSubview:self.TitleV];
//    [self.view addSubview:view];
//    [self.TitleV addSubview:self.viewBlcak];

//    self.scroView.backgroundColor = [UIColor redColor];
//
//    [self.scroView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.TitleV.mas_bottom).offset(0);
//        make.left.right.equalTo(self.view).offset(0);
//        make.bottom.equalTo(self.view).offset(-TabbarHeight);
//    }];

}




-(UIView *)viewBlcak{
    if (!_viewBlcak) {
        _viewBlcak = [[UIView alloc]initWithFrame:CGRectMake(0, backHeight, kScreenW/3.0, 3)];
        _viewBlcak.backgroundColor = [UIColor blackColor];
    }
    return _viewBlcak;
}

//平滑曲线
-(Ugc_Main_ScrollView_WX *)scroView{
    if (!_scroView) {
        _scroView = [[Ugc_Main_ScrollView_WX alloc]initWithFrame:CGRectMake(0, 40+44, kScreenW, 0)];
    }
    return  _scroView;
}


//-(MainTitleV *)TitleV{
//    if (!_TitleV) {
//
//        _TitleV = [[MainTitleV alloc]initWithFrame:CGRectMake(0,kStatusBarHeight, SCREEN_WIDTH, 40)];
//        _TitleV.state = 0;
//
//        //        _TitleV.backgroundColor = [UIColor randomColor];
//        /* FIXME: ================= 新首页 UI 修改 ================= */
//
//        [_TitleV setShadowType1WithColor:[UIColor defaultShadowColor] offset:CGSizeMake(0, 5) opacity:1 radius:3];
//
//        NSMutableArray *arrMSelect = [[NSMutableArray alloc]initWithArray:@[@"关注",@"精选",@"动态"]];
//        NSMutableArray *arrMNormal = [[NSMutableArray alloc]initWithArray:@[@"关注",@"精选",@"动态"]];
//
//        _TitleV.arrMSelect = [[NSMutableArray alloc]initWithArray:arrMSelect];
//
//        _TitleV.arrMNormal = [[NSMutableArray alloc]initWithArray:arrMNormal];
//
//        @weakify(self);
//        [_TitleV setBlcokIndex:^(NSInteger index) {
//            @strongify(self);
//            self.scroView.contentOffset = CGPointMake((index-100)*kScreenW, 0);
//            //            [self setBackViewFrame:index];
//        }];
//    }
//    return _TitleV;
//}



-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden=NO;
    [self.scroView.tbv1 setHeadView];
    if (kUSER_INFO_MANAGER.arrMUgcReleaseFailure.count>0) {
        self.filaSendView.hidden = NO;
        
        self.scroView.tbv1.contentInset = UIEdgeInsetsMake(CGRectGetMaxY(self.TitleV.frame)-40, 0, 0, 0);
        self.scroView.tbv2.contentInset = UIEdgeInsetsMake(CGRectGetMaxY(self.TitleV.frame)-40, 0, 0, 0);
        self.scroView.tbv3.contentInset = UIEdgeInsetsMake(CGRectGetMaxY(self.TitleV.frame)-40, 0, 0, 0);

    }else{
        self.filaSendView.hidden = YES;
        self.scroView.tbv1.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
        self.scroView.tbv2.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
        self.scroView.tbv3.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);

    }
    
    if (!self.isfirst) {
        //第一次进来显示杂志
        if (kUSER_INFO_MANAGER.userIsLogin) {
            self.viewBlcak.frame = CGRectMake(kScreenW/3.0, backHeight, kScreenW/3.0, 3);
            self.scroView.contentOffset = CGPointMake(kScreenW, 0);
            self.isfirst = YES;
//            if (kUSER_INFO_MANAGER.userIsLogin) {
                self.viewBlcak.frame = CGRectMake(kScreenW/3.0, backHeight, kScreenW/3.0, 3);
//            }else{
//                self.viewBlcak.frame = CGRectMake(0, backHeight, kScreenW/2.0, 3);
//            }
            self.isUserIsLogin = kUSER_INFO_MANAGER.userIsLogin;
        }else{
            NSLog(@"");
//            self.viewBlcak.frame = CGRectMake(0, backHeight, kScreenW/2.0, 3);
        }
    }else{
        
    }
    
    if (self.isUserIsLogin != kUSER_INFO_MANAGER.userIsLogin) {
        if (kUSER_INFO_MANAGER.userIsLogin) {
            self.scroView.contentOffset = CGPointMake(0, 0);
            self.viewBlcak.frame = CGRectMake(0, backHeight, kScreenW/3.0, 3);
        }else{
            self.scroView.contentOffset = CGPointMake(0, 0);
//            self.viewBlcak.frame = CGRectMake(0, backHeight, kScreenW/2.0, 3);
        }
        self.isUserIsLogin = kUSER_INFO_MANAGER.userIsLogin;
    }
    
    if (kUSER_INFO_MANAGER.userIsLogin) {
//        self.btn1.hidden = NO;
//        self.btn2.frame = CGRectMake(kScreenW/3.0, kStatusBarHeight2+10, kScreenW/3.0, 40);
//        self.btn3.frame = CGRectMake(kScreenW/3.0*2, kStatusBarHeight2+10, kScreenW/3.0, 40);
//        self.scroView.tbv1.hidden = NO;
//        self.scroView.tbv2.frame = CGRectMake(kScreenW, 0, kScreenW, kScreenH-kBottomSafeHeight-84);
//        self.scroView.tbv3.frame = CGRectMake(kScreenW*2, 0, kScreenW, kScreenH-kBottomSafeHeight-84);
//        self.scroView.contentSize = CGSizeMake(kScreenW*3, 0);

    }else{
//        self.btn1.hidden = YES;
//        self.btn2.frame = CGRectMake(0, 44, kScreenW/2.0, 40);
//        self.btn3.frame = CGRectMake(kScreenW/2.0, 44, kScreenW/2.0, 40);
//
//        self.scroView.tbv1.hidden = YES;
//        self.scroView.tbv2.frame = CGRectMake(0, 0, kScreenW, kScreenH-kBottomSafeHeight-84);
//        self.scroView.tbv3.frame = CGRectMake(kScreenW, 0, kScreenW, kScreenH-kBottomSafeHeight-84);
//        self.scroView.contentSize = CGSizeMake(kScreenW*2, 0);
    }
    
    /** 处理发布页面tabbar显示问题 */
    if ([DEFAULReleaseV iseqHidden]) {
        [self.tabBarController.tabBar setHidden:NO];
    }else{
        [self.tabBarController.tabBar setHidden:YES];
    }
    if (kUSER_isPublishImage.type == YES && !kUSER_isPublishImage.typeClose) {
        kUSER_isPublishImage.hidden = NO;
    }
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    if (kUSER_isPublishImage.type == YES && !kUSER_isPublishImage.typeClose) {
        kUSER_isPublishImage.hidden = YES;
    }
    
}

-(failToSendView *)filaSendView{
    if (!_filaSendView) {
        _filaSendView = [[failToSendView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 45)];
        [self.view addSubview:_filaSendView];
        [_filaSendView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.TitleV.mas_bottom).offset(0);
            make.left.right.equalTo(self.view).offset(0);
            make.height.mas_equalTo(45);
        }];
    }
    return _filaSendView;
}



-(Main_Title_View_WX *)TitleV{
    if (!_TitleV) {
        _TitleV = [[Main_Title_View_WX alloc]initWithFrame:CGRectMake(0,kStatusBarHeight, SCREEN_WIDTH, 40 )];
        _TitleV.backgroundColor = [UIColor whiteColor];
        [_TitleV setShadowType1WithColor:[UIColor defaultShadowColor] offset:CGSizeMake(0, 5) opacity:1 radius:3];

//        NSMutableArray *arrMNormal = [[NSMutableArray alloc]initWithArray:@[@"关注",@"精选",@"动态"]];
//        _TitleV.arrMNormal = arrMNormal;
        _TitleV.state = MainTitleVStateUGC;
        
        
        @weakify(self);
        [_TitleV setBlcokIndex:^(NSInteger index) {
            @strongify(self);
            self.scroView.contentOffset = CGPointMake((index)*kScreenW, 0);
        }];
    }
    return _TitleV;
}


-(UgcMain_First_Tbv_WX *)tbv{
    if (!_tbv) {
        _tbv = [[UgcMain_First_Tbv_WX alloc]initializeFrame:CGRectMake(0, 0, 1, 1) isMj:1 isEstimatedRowHeight:YES addRegisterNib:@[@"Ugc_Friends_OnePicCell_WX",@"Ugc_Friends_FourPicCell_WX",@"Ugc_Friends_MorePicCell_WX",@"UgcMain_FirstOnePic_Cell_WX",@"UgcMain_FirstFourPic_Cell_WX",@"UgcMain_FirstMorePic_Cell_WX"]];
    }
    return _tbv;    
}

@end
